package com.qifenqian.turbot.module.adapter.marketing

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.qifenqian.turbot.R
import kotlinx.android.synthetic.main.item_discount_dish_child.view.*

/**
 * @author H
 * @createTime 2018/12/24 19:08
 * @description 用户评论中的图片适配器
 * @see
 * @since
 */
class DiscountDishChildAdapter(context: Context, list: List<String>) : RecyclerView.Adapter<DiscountDishChildAdapter.ImageViewHolder>() {

    private var mContext: Context? = null
    private var mList: List<String>? = mutableListOf()

    init {
        mContext = context
        mList = list
    }

    override fun onCreateViewHolder(parent: ViewGroup, p1: Int): ImageViewHolder {
        val view = LayoutInflater.from(mContext).inflate(R.layout.item_discount_dish_child, parent, false)
        return ImageViewHolder(view)
    }

    override fun getItemCount(): Int {
        return mList!!.size
    }

    override fun onBindViewHolder(holder: ImageViewHolder, i: Int) {
        holder.itemView.tv_item_discount_dish_child_name.text = mList!![i]
        holder.itemView.tv_item_discount_dish_child_discount.text = mList!![i]
        holder.itemView.setOnClickListener {
            if (mOnDishDiscountClickListener != null) {
                mOnDishDiscountClickListener!!.onClick(i)
            }
        }
    }

    class ImageViewHolder(view: View) : RecyclerView.ViewHolder(view)

    fun setOnDishDiscountClickListener(onDishDiscountClickListener: OnDishDiscountClickListener) {
        mOnDishDiscountClickListener = onDishDiscountClickListener;
    }

    private var mOnDishDiscountClickListener: OnDishDiscountClickListener? = null

    interface OnDishDiscountClickListener {
        fun onClick(position: Int)
    }
}
